package com.atguigu.gmall.payment.weixin.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.payment.weixin.pojo.WeiXinVO;
import com.atguigu.gmall.payment.weixin.service.WeiXinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/api/payment/weixin")
public class WeiXinController {
    @Autowired
    WeiXinService weiXinService;

    ///createNative/905906751461654500
    @GetMapping("/createNative/{orderId}")
    public Result weiXinPay(@PathVariable String orderId) {
        WeiXinVO weiXinVO = weiXinService.weiXinPay(Long.parseLong(orderId));
        return Result.ok(weiXinVO);
    }




    @GetMapping("/queryPayStatus/{orderId}")
    public Result queryPayStatus(@PathVariable String orderId) {
        boolean isPay = weiXinService.queryPayStatus(Long.parseLong(orderId));
        if (isPay) {
            return Result.ok();
        }else {
            return Result.build("", ResultCodeEnum.PAY_RUN);
        }
    }
}
